package com.wcl.demo.ui.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.wcl.demo.R;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by dllo on 15/11/25.
 */
public class TextViewTestActivity extends Activity implements View.OnClickListener {
    private TextView test_textView, test_textView2;
    private EditText editText1122;
    private Button kjhgfds_btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_text_view_test);
        initView();
    }

    private void initView() {
        test_textView = (TextView) findViewById(R.id.test_textView);
        test_textView2 = (TextView) findViewById(R.id.test_textView2);
        editText1122= (EditText) findViewById(R.id.editText1122);
        kjhgfds_btn= (Button) findViewById(R.id.kjhgfds_btn);
        test_textView.setOnClickListener(this);
        initData();
    }

    private void initData() {
        String haha = "噢哈哈哈哈哈哈哈哈哈哈oooooooooooooooooo哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈g噢噢g哈,./,.噢g哈哈jhgdfg噢./哈sa噢,./哈lyf,./d噢哈噢g哈sagj噢,噢哈哈h./gdfsa";
//        String haha = ";lkjhgfdsa[poiuytrewmnbvcxuytfrdkjmnbasdfasdfcf,./,.";
//        ToDBC(stringFilter(haha));
//        stringFilter(haha);
//        test_textView.setText(ToDBC(stringFilter(haha)));
        String cc=ToSBC(haha);
        test_textView.setText(cc+"");
        test_textView2.setText(haha);

    }

    //导致TextView异常换行的原因：安卓默认数字、字母不能为第一行以后每行的开头字符，因为数字、字母为半角字符
    //所以我们只需要将半角字符转换为全角字符即可，方法如下
    public static String ToSBC(String input) {
        char c[] = input.toCharArray();
        for (int i = 0; i < c.length; i++) {
            if (c[i] == ' ') {
                c[i] = '\u3000';
            } else if (c[i] < '\177') {
                c[i] = (char) (c[i] + 65248);
            }
        }
        return new String(c);
    }
    /**
     * 去除特殊字符或将所有中文标号替换为英文标号
     *
     * @param str
     * @return
     */
    public static String stringFilter(String str) {
        str = str.replaceAll("【", "[").replaceAll("】", "]")
                .replaceAll("！", "!").replaceAll("：", ":");// 替换中文标号
        String regEx = "[『』]"; // 清除掉特殊字符
        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher(str);
        return m.replaceAll("").trim();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.test_textView:
//                editText1122.getText();
                test_textView.setText(editText1122.getText());
                break;
        }
    }
}
